Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit 0ebdb9c8265e72447d0c6777e5f78c12f931c913


Parents : 52dfebc
Author : Mark Qvist <mark@unsigned.io>
Date : 2022-12-20T00:38:46+01:00

Added automatic deregistering from peered LXMF propagation nodes when disabling node hosting

Changes

1 files changed, 14 insertions(+), 0 deletions(-)


Diff

diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py
index 2dea9ad..1211e32 100644
--- a/nomadnet/NomadNetworkApp.py
+++ b/nomadnet/NomadNetworkApp.py
@@ -98,6 +98,7 @@ class NomadNetworkApp:
self.ignoredpath = self.configdir+"/ignored"
self.logfilepath = self.configdir+"/logfile"
self.errorfilepath = self.configdir+"/errors"
+ self.pnannouncedpath = self.configdir+"/pnannounced"
self.storagepath = self.configdir+"/storage"
self.identitypath = self.configdir+"/storage/identity"
self.cachepath = self.configdir+"/storage/cache"
@@ -296,11 +297,24 @@ class NomadNetworkApp:
RNS.log("Cannot prioritise "+str(dest_str)+", it is not a valid destination hash", RNS.LOG_ERROR)
self.message_router.enable_propagation()
+ try:
+ with open(self.pnannouncedpath, "wb") as pnf:
+ pnf.write(msgpack.packb(time.time()))
+ pnf.close()
+ except Exception as e:
+ RNS.log("An error ocurred while writing Propagation Node announce timestamp. The contained exception was: "+str(e), RNS.LOG_ERROR)
RNS.log("LXMF Propagation Node started on: "+RNS.prettyhexrep(self.message_router.propagation_destination.hash))
self.node = nomadnet.Node(self)
else:
self.node = None
+ if os.path.isfile(self.pnannouncedpath):
+ try:
+ RNS.log("Sending indication to peered LXMF Propagation Node that this node is no longer participating", RNS.LOG_DEBUG)
+ self.message_router.disable_propagation()
+ os.unlink(self.pnannouncedpath)
+ except Exception as e:
+ RNS.log("An error ocurred while indicating that this LXMF Propagation Node is no longer participating. The contained exception was: "+str(e), RNS.LOG_ERROR)
RNS.Transport.register_announce_handler(nomadnet.Conversation)
RNS.Transport.register_announce_handler(nomadnet.Directory)


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────